//
//  InviteViewController.swift
//  iModern
//
//  Created by Ralf on 5/25/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

import UIKit

class InviteViewController: TableViewController
{
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
//    let webChatDelegate = WebchatDelegate()
//    let weiboDelegate   = WeiboDelegate()
    var parameters  = NSMutableDictionary()

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.tableView.registerNib(UINib(nibName: "InviteViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "Invite")
        //self.tableView.tableHeaderView =
        self.initBackButton()
    }

    override func viewWillAppear(animated: Bool)
    {
        self.navigationItem.title = "邀请好友"
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int
    {
        return 1
    }

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    {

        return 80; }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {

        return 5
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("Invite", forIndexPath: indexPath) as! InviteViewCell
        if indexPath.row == 0
        {
            cell.categoryImage.hidden = true
            cell.categoryLabel.hidden = true
            let label = UILabel(frame: CGRectMake(0, 30, UIScreen.mainScreen().bounds.size.width, 30))
            label.textAlignment = NSTextAlignment.Center
            label.font = UIFont.systemFontOfSize(19)
            label.text = "独乐乐不如众乐乐，一起玩来~"
            cell.addSubview(label)
        }

        if indexPath.row == 1
        {
            cell.categoryImage.image = UIImage(named: "Weibo-60")
            cell.categoryLabel.text = "邀请微博好友"
        }
        if indexPath.row == 2
        {
            cell.categoryImage.image = UIImage(named: "Webchat-60")
            cell.categoryLabel.text = "邀请微信好友"
        }
        if indexPath.row == 3
        {
            cell.categoryImage.image = UIImage(named: "QQ-60")
            cell.categoryLabel.text = "邀请QQ好友"
        }
        if indexPath.row == 4
        {
            cell.categoryImage.image = UIImage(named: "Phone-60")
            cell.categoryLabel.text = "邀请通讯录好友"
        }
        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {
//        self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
//        parameters.removeAllObjects()
//
//        if (indexPath.row == 1)
//        {
//            //            if ((appDelegate.parameterManager.parameters["WeiboToken"]) == nil)
//            //            {
//            //                weiboDelegate.login()
//            //            }
//            //            else
//            //            {
//            parameters.setValue("我在iModern爱魔登,你在哪里?@你的朋友", forKey: "shareText")
//            parameters.setValue(nil, forKey: "shareImageData")
//            parameters.setValue(appDelegate.parameterManager.parameters["WeiboToken"], forKey: "access_token")
//            weiboDelegate.share(parameters as [NSObject:AnyObject])
//            //            }
//        }
//
//        if (indexPath.row == 2)
//        {
//            webChatDelegate.shareToSomeOne()
//            //webChatDelegate.weixinPay("209", tip: 0.01)
//        }
//
//        if (indexPath.row == 3)
//        {
//            parameters.setValue("我在iModern爱魔登,你在哪里?", forKey: "description")
//            appDelegate.shareQQToSomeOne(parameters)
//        }
//        if (indexPath.row == 4)
//        {
//            let controller = InviteFromViewController()
//            self.navigationController?.pushViewController(controller, animated: true)
//        }
    }
    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return NO if you do not want the specified item to be editable.
    return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    // Delete the row from the data source
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
    
    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return NO if you do not want the item to be re-orderable.
    return true
    }
    */

    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    }
    */

}
